$(function () {
    $('#myTable').dataTableExtend({
        "ajax": {
            "url": sysInfo.basePath + "/zs/general_credential/get_return_certificate.do",
            "type": "post"
        }, "fnServerParams": function (aoData) {
            var checkResult = checkHasSybAuth($('#signOrgId option'));
            if (!checkResult) {
                aoData = $.extend(aoData, {"isAll": "0"});
            }
            aoData = $.extend(aoData, $('.titleSearch').serialize2object());
            return aoData;
        },
        "pageLength": 20,//每页显示的条数默认是10条，有特殊业务需要显示不同条数的列表才应该加入该参数
        "scrollX": true,//是否开启横项滚动
        "fixedColumns": {//锁定列，只有开启scrollX时才生效
            "leftColumns": 3,//左侧锁定2列
            "rightColumns": 2//右侧锁定1列
        },
        "aoColumns": [
            {
                "title": "序号",
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return meta.row + 1;
                }
            },
            {
                "title": "所属事业部",
                "data": "signOrgName",
                "orderable": false
            },
            {
                "title": "退回时间",
                "data": "lastOutgoingTime",
                "orderable": false
            },
            {
                "title": "生产订单编号",
                "data": "scOrderNo",
                "orderable": false,
                "render": function (data, type, row, meta) {
                    if (!data) {
                        return "";
                    }
                    return "<a href='javascript:void(0);'  class='layui-table-link' onclick='openOrderInfoDetail(\"" + data + "\",\"" + row.scOrderId + "\")'>" + data + "</a>";
                }
            },
            {
                "title": "收证商务",
                "data": "collectorName",
                "orderable": false,
            },
            {
                "title": "证书编号",
                "data": "certificateNo",
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return full.certificateName + "<br/><a href='javascript:void(0);'  class='layui-table-link' onclick='credentialDetail(\"" + data + "\",\"" + full.baseId + "\")'>" + data + "</a>";
                }
            },
            {
                "title": "持证人/身份证号码",
                "data": "personalIdCard",
                "orderable": false,
                "render": function (data, type, row, meta) {
                    return row.personalName + "<br/><span>" + hideIdCard(data) + "</span>";
                }
            },
            {
                "title": "类型/专业/等级",
                "data": "certificateSpecialtys",
                "orderable": false,
                "render": function (data, type, row, meta) {
                    data = (null != data && "" != data) ? data : "";
                    return row.certificateType + "<div title='" + data + "' class='f-toe' style=\"max-width:100px;word-wrap:break-word\">" + data + "</div>" + row.certificateLevel;
                }
            },
            {
                "title": "类别",
                "data": "certificateCategory",
                "orderable": false,
                "render": function (data, type, row, meta) {
                    return data;
                }
            },
            {
                "title": "在库状态",
                "data": "libraryStatus",
                "orderable": false,
                "render": function (data, type, row, meta) {
                    return data;
                }
            },
            {
                "title": "地区",
                "orderable": false,
                "render": function (data, type, row, meta) {
                    areaProvince = (null != row.areaProvince && "" != row.areaProvince) ? row.areaProvince : "";
                    area = (null != row.certificateArea && "" != row.certificateArea) ? "/" + row.certificateArea : "";
                    return areaProvince + area;
                }

            },
            {
                "title": "适用范围",
                "data": "applicationScope",
                "orderable": false
            },
            {
                "title": "最新入库时间",
                "data": "lastWarehousingTime",
                "orderable": false
            },
            {
                "title": "操作",
                "orderable": false,
                "data": "certificateNo",
                "render": function (data, type, row, meta) {
                    return "<a href='javascript:void(0);'  class='layui-table-link' onclick='credentialDetail(\"" + data + "\",\"" + row.baseId + "\")'>查看</a>";
                }
            }
        ],
    });

    // 加载事业部
    syb('[name="signOrgId"]');
    loadCertificateType('190px', '#certificateType', $("#generalType").val(), 0);

    //异步加载
    Plug.plug_ins(
        "get",
        cmsBaseUrl + "/api/cms/tree_book/v1/get_tree_book_list.do?code=2147483647&type=2&level=1",
        "#certificateArea",
        '请选择地区',
        function () {
        },
        true, '2147483647'
    );
});

/**
 * 导出退回证书
 * @returns {boolean}
 */
function exportReturnCertificate() {
    var params = $("#titleSearch").serializeObject();
    var isNotNull = 0;
    $.each(params, function (i, item) {
        if (!checkIsEmpty(item)) {
            isNotNull = isNotNull + 1;
            return false;
        }
    });
    if (isNotNull === 0) {
        DGG.Errors("请选择搜索条件后进行导出!");
        return false;
    }
    var checkResult = checkHasSybAuth($('#signOrgId option'));
    if (!checkResult) {
        params["isAll"] = "0";
    }
    export_table("/zs/general_credential/export_return_credential.do", params);
}

